package per.liuchengyin.alipay.config;


import lombok.extern.log4j.Log4j2;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@Log4j2
public class RabbitmqConfig {

    //1.声明一个业务的交换机 一个

    @Bean
    public FanoutExchange priceExchange(){
        return new FanoutExchange("priceExchange");
    }

    @Bean
    public Queue biaQueue1(){
        Map<String,Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange","deadLetterExchange");
        args.put("x-dead-letter-routing-key","deadKey1");
        args.put("x-message-ttl",60000);
        return QueueBuilder.durable("biaQueue1").withArguments(args).build();

    }



    @Bean
    public  Binding binding1(@Qualifier("biaQueue1")Queue queue,@Qualifier("priceExchange")FanoutExchange exchange){
        return BindingBuilder.bind(queue).to(exchange);
    }


    @Bean("priceLetterExchange")
    public DirectExchange priceLetterExchange(){
        return new DirectExchange("priceLetterExchange");
    }

    @Bean("priceLetterQueue")
    public Queue priceLetterQueueA(){
        return new Queue("priceLetterQueue");
    }

    @Bean
    public Binding priceLetterBindingA(@Qualifier("priceLetterQueue")Queue queue,@Qualifier("priceLetterExchange")DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("deadKey1");
    }
}
